// "use client"
// import { useState } from 'react';
// import { ethers } from 'ethers';
// import Web3 from 'web3';

// export default function WalletConnector() {
//   const [account, setAccount] = useState(null);
//   const [signature, setSignature] = useState(null);
//   let provider;

//   const connectWallet = async (walletType) => {
//     if (typeof window.ethereum !== 'undefined') {
//       try {

//         if (walletType === 'metamask') {
//           provider = window.ethereum;
//         } else if (walletType === 'okx') {
//           provider = window.okxwallet; // 假设 OKX 钱包在 window 对象中暴露为 okxwallet
//         }

//         const addr = await provider.request({ method: 'eth_requestAccounts' });
//         setAccount(addr)
//         const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
//         const signer = web3Provider.getSigner();
//         const address = await signer.getAddress();
//         console.log(address);

//         setAccount(address);
//       } catch (error) {
//         console.error('Error connecting to wallet:', error);
//       }
//     } else {
//       alert('No Ethereum provider found. Install MetaMask or OKX Wallet.');
//     }
//   };

//   const signMessage = async () => {
//     provider=window.ethereum
//     console.log(account);
//     provider.getBalance()
    
//     const message = "Hello";
//     const sign = await provider.request({
//       method: 'eth_sign',
//       params: [account, message],
//     });
//     setSignature(sign)
//   }
//   return (
//     <div>
//       <button onClick={() => connectWallet('metamask')}>Connect MetaMask</button>
//       <button onClick={() => connectWallet('okx')}>Connect OKX Wallet</button>
//       <button onClick={() => signMessage()}>sign</button>
//       {account && <p>Connected account: {account}</p>}
//       <div>signature: {signature}</div>
//     </div>
//   );
// }